<template>
    <div>
        <table class="list">
            <thead>
                <tr>
                    <th>姓名</th>
                    <th>性别</th>
                    <th>年龄</th>
                    <th>操作</th>
                </tr>
            </thead>
            <tbody>
                <tr v-for="stu in students" :key="stu._id">
                    <td>{{stu.name}}</td>
                    <td>{{stu.gender}}</td>
                    <td>{{stu.age}}</td>
                    <td>
                        <button type="button" @click="handleUpdate(stu._id)">修改</button>
                        <button type="button">删除</button>
                    </td>
                </tr>
            </tbody>
        </table>
    </div>
</template>

<script>
import {getById} from '../../services/student'
export default {
    props:["students"],
    methods:{
        async handleUpdate(id){
            let {data} = await getById(id);
            console.log(data);
            this.$emit('setStudent',data);
        }
    }
};
</script>

<style>
.list {
    border-collapse: collapse;
}
th,
td {
    border: 1px solid black;
}
</style>